package com.baidu.service.impl;

import com.baidu.utils.ResultResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.pojo.TbSeller;
import com.baidu.service.TbSellerService;
import com.baidu.mapper.TbSellerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class TbSellerServiceImpl extends ServiceImpl<TbSellerMapper, TbSeller>
    implements TbSellerService{

    @Autowired
    private TbSellerMapper sellerMapper;

    @Override
    public ResultResponse sellerLogin(String userName, String passWord) {
        LambdaQueryWrapper<TbSeller> last = new QueryWrapper<TbSeller>().lambda().eq(TbSeller::getNickName, userName).last("limit 1");

        TbSeller tbSeller = sellerMapper.selectOne(last);

        if(tbSeller==null){
            return ResultResponse.FAILED(-1,"登录名称不存在");
        }

        if(!passWord.equals(tbSeller.getPassword())){
            return ResultResponse.FAILED(-1,"密码错误");
        }

        return ResultResponse.SUCCESS("登录成功");
    }

    @Override
    public ResultResponse getSellerBySellerId(String sellerId) {
        LambdaQueryWrapper<TbSeller> last = new QueryWrapper<TbSeller>().lambda().eq(TbSeller::getSellerId, sellerId).last("limit 1");

        TbSeller tbSeller = sellerMapper.selectOne(last);

        return ResultResponse.SUCCESS(tbSeller);
    }


    @Override
    public ResultResponse updSeller(TbSeller seller) {
        int i = sellerMapper.updateById(seller);
        return ResultResponse.SUCCESS("密码修改成功");
    }
}




